<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
class addin
{
	var $CI;
	public function getcounter()
	{
		$this->CI=&get_instance();
		$ip = $this->CI->session->userdata('session_id');
		$query = $this->CI->db->get_where('lp_hits', array('ip' => $ip),1,0);
		$query = $query->row_array();
		if (count($query) < 1 )
		{
			$this->CI->db->insert('lp_hits', array('ip' => $ip) );
		}
		return $this->CI->db->count_all('lp_hits');
	}
	public function getonline()
	{
		$this->CI=&get_instance();
		return $this->CI->db->count_all('lp_sessions');
	}
	public function getMenuMain()
	{
		$str = '<ul>';
		$arrLink = array(
			base_url(),
			base_url('gioithieu.html'),
			base_url('sanpham.html'),
			base_url('dichvu.html'),
			base_url('tintuc.html'),
			base_url('tuvan.html'),
			base_url('lienhe.html')
		);
		$arrName = array(
			'TRANG CHỦ',
			'GIỚI THIỆU',
			'SẢN PHẨM',
			'DỊCH VỤ',
			'TIN TỨC',
			'TƯ VẤN',
			'LIÊN HỆ'
		);
		for($i=0;$i<count($arrLink);$i++)
		{
            if($i==count($arrLink)-1)
            {
                $str.='<li style="border-right:none"><a href="'.$arrLink[$i].'"><span>'.$arrName[$i].'</span></a></li>';
            }
            else
            {
			    $str.='<li><a href="'.$arrLink[$i].'"><span>'.$arrName[$i].'</span></a></li>';

            }
		}
		$str.='</ul>';
		return $str;
	}
	public function getMenuTin()
	{
		$str = NULL;
		$this->CI=&get_instance();
		$this->CI->load->model('loaitin_model');
		$result = $this->CI->loaitin_model->getDDL();
		foreach($result as $item)
		{
			$str.='<a href="'.base_url('tintuc/loaitin/'.$item->tenUrl).'.html">'.$item->ten.'</a> - ';
		}
		$str = substr($str,0,strlen($str)-3);
		return $str;
	}
	public function getMenu3Cap()
	{
		$str3 = NULL;
		$result1 = $this->_getChungLoai();
		foreach($result1 as $item1)
		{
			$result2 = $this->_getLoaiPhong($item1->id);
			$str3.="<div id='divSideBar'><ul>";
			foreach($result2 as $item2)
			{
				$result3 = $this->_getLoai($item1->id, $item2->id);
				$str3 .= '<li><a href="'.base_url('sanpham/loaiphong/'.$item2->tenUrl.'.html').'">- '.$item2->ten.'</a><ul>';
				foreach($result3 as $item3)
				{
					$str3 .= '<li><a href="'.base_url('sanpham/loaisanpham/'.$item3->tenUrl.'.html').'">'.$item3->ten.'</a></li>';
				}
				$str3 .= '</ul>';
			}
			$str3.='</li></ul><div id="divBgMenuSideBar"><span><img src = "'.base_url('image/src/L-7.png').'" />'.$item1->ten.'</span></div></div>';
		}
		return $str3;
	}
	
	public function thongKe()
	{
		$str4 = NULL;
		$str4 .="<div id='divSideBar'><span id='spanThongKe'></span><span>Tổng số truy cập:".$this->getcounter();
		$str4.="</span><span style='padding-bottom:15px;'>Đang truy cập:".$this->getonline();
		$str4.="</span><div id='divBgMenuSideBar'><span><img src='".base_url('image/src/L-7.png')."' />Tổng số truy cập</span></div></div>";
	return $str4;
	}
	
	function _getChungLoai()
	{
		$this->CI=&get_instance();
		$this->CI->load->model('chungloai_model');
		return $this->CI->chungloai_model->getDDL();
	}
	function _getLoaiPhong($idCL)
	{
		$this->CI=&get_instance();
		$this->CI->load->model('loaiphong_model');
		return $this->CI->loaiphong_model->getDDL($idCL);
	}
	function _getLoai($idCL,$idLP)
	{
		$this->CI=&get_instance();
		$this->CI->load->model('loai_model');
		return $this->CI->loai_model->getDDL($idCL,$idLP);
	}
}